import { Ollama } from "@langchain/ollama";
import * as fs from "node:fs/promises";
import { PromptTemplate } from "@langchain/core/prompts";



const llm = new Ollama({
    model: "qwen3:0.6b", // Default value
    temperature: 0,
    maxRetries: 2,
    // other params...
});
const prompt = PromptTemplate.fromTemplate(
    "请将以下内容 '{input}' 翻译成 {output_language}，并且确保只使用 {output_language} 来表达。\n"
);
const chain = prompt.pipe(llm);

const imageData = await fs.readFile("./images/OIP-C1.png");

const base64Image = imageData.toString("base64");
const model = new Ollama({
    model: "llava:7b",
}).bind({
    images: [base64Image],
});

const res = await model.invoke("图片中有什么?");
console.log(res)

const translate = async (input, outputLanguage = 'Chinese') => {
    const completion = await chain.invoke({
        output_language: outputLanguage,
        input: input
    });
    return completion;
}

const translation = await translate(res);
console.log(translation);
